import Mock from 'mockjs'

import { downLoadFile, upLoadFile } from './file/file'
import { login, logOut, menuList, onlineInfo, userInfo } from './oauth/oauth'
import { deleteRuntime, queryRuntime, updateRuntime } from './sysconfig/runtime'
import { deleteApp, getAppList, queryApp, updateApp } from './sysconfig/application'
import { deleteOrg, getOrgInfo, getOrgList } from './sysconfig/organization'
import { deleteUser, getModUserList, getUserList, resetSuccess, updateUser } from './sysconfig/user'
import {
  deleteRole,
  getRoleCodeList,
  getRoleInfo,
  getRoleList,
  getRoleListOption,
  updateRole
} from './sysconfig/role'
import {
  deleteAuth,
  getAllMenuList,
  getMenuInfo,
  getMenuListByAppId,
  getModuleFuncCodeList,
  getModuleFuncInfo,
  getModuleFuncListByAppId
} from './sysconfig/auth'

// 配置Ajax请求延时，可用来测试网络延迟大时项目中一些效果
Mock.setup({
  timeout: 1000
})

Mock.mock(/\/file\/upload/, /post/i, upLoadFile)
Mock.mock(/\/file\/download/, /post/i, downLoadFile)
Mock.mock(/\/server\/token/, /post/i, login)
Mock.mock(/\/server\/logout/, /post/i, logOut)
Mock.mock(/\/server\/online-info/, /get/i, onlineInfo())
Mock.mock(/\/server\/user-info/, /get/i, userInfo)
Mock.mock(/\/server\/menu-list/, /get/i, menuList)
Mock.mock(/\/server\/user-info/, /(patch)|(put)/i, function (options) {
  return Object.assign(userInfo(), JSON.parse(options.body))
})
Mock.mock(/\/server\/runtime/, /(get)|(put)|(patch)/i, updateRuntime)
Mock.mock(/\/server\/runtime/, /delete/i, deleteRuntime)
Mock.mock(/\/server\/runtime/, /post/i, queryRuntime)
Mock.mock(/\/server\/app/, /(put)|(patch)/i, updateApp)
Mock.mock(/\/server\/app\/update-secret/, /get/i, updateApp)
Mock.mock(/\/server\/app/, /get/i, getAppList)
Mock.mock(/\/server\/app/, /delete/i, deleteApp)
Mock.mock(/\/server\/app/, /post/i, queryApp)
Mock.mock(/\/server\/org\/.*/, /get/i, getOrgInfo)
Mock.mock(/\/server\/org/, /get/i, getOrgList)
Mock.mock(/\/server\/org/, /put/i, getOrgInfo)
Mock.mock(/\/server\/org/, /patch/i, function (options) {
  return Object.assign(getOrgInfo(), JSON.parse(options.body))
})
Mock.mock(/\/server\/org/, /delete/i, deleteOrg)
Mock.mock(/\/server\/mod-user-list/, /get/i, getModUserList)
Mock.mock(/\/server\/role\/role-code-list/, /get/i, getRoleCodeList)
Mock.mock(/\/server\/role\/.*/, /get/i, getRoleInfo)
Mock.mock(/\/server\/role/, /get/i, getRoleList)
Mock.mock(/\/server\/role/, /put/i, updateRole)
Mock.mock(/\/server\/role/, /patch/i, function (options) {
  return Object.assign(updateRole(), JSON.parse(options.body))
})
Mock.mock(/\/server\/role/, /delete/i, deleteRole)
Mock.mock(/\/server\/role\/role-list\/.*/, /get/i, getRoleListOption)
Mock.mock(/\/server\/auth\/menu-list\/.*/, /get/i, getMenuListByAppId)
Mock.mock(/\/server\/auth\/module-func-list\/.*/, /get/i, getModuleFuncListByAppId)
Mock.mock(/\/server\/auth\/module-func-code-list/, /get/i, getModuleFuncCodeList)
Mock.mock(/\/server\/auth\/menu/, /get/i, getAllMenuList)
Mock.mock(/\/server\/auth\/menu/, /put/i, function (options) {
  return Object.assign({ id: 'testId' }, JSON.parse(options.body))
})
Mock.mock(/\/server\/auth\/menu\/.*/, /get/i, getMenuInfo)
Mock.mock(/\/server\/auth\/menu/, /patch/i, function (options) {
  return Object.assign(getMenuInfo(), JSON.parse(options.body))
})
Mock.mock(/\/server\/auth\/menu/, /delete/i, deleteAuth)
Mock.mock(/\/server\/auth\/module-func/, /get/i, function (options) {
  return Object.assign({ id: 'testId' }, JSON.parse(options.body))
})
Mock.mock(/\/server\/auth\/module-func/, /put/i, getModuleFuncInfo)
Mock.mock(/\/server\/auth\/module-func\/.*/, /get/i, getModuleFuncInfo)
Mock.mock(/\/server\/auth\/module-func/, /patch/i, function (options) {
  return Object.assign(getModuleFuncInfo(), JSON.parse(options.body))
})
Mock.mock(/\/server\/auth\/module-func/, /delete/i, deleteAuth)
Mock.mock(/\/server\/user/, /post/i, getUserList)
Mock.mock(/\/server\/user/, /delete/i, deleteUser)
Mock.mock(/\/server\/user\/reset-pwd\/.*/, /get/i, resetSuccess)
Mock.mock(/\/server\/user/, /(put)|(patch)/i, updateUser)
